<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>提现订单处理</title>
	<%@ include file="/view/common/tags.jsp"%>
	<script type="text/javascript" src="${sysManagerV1}/js/My97DatePicker/WdatePicker.js"> </script>
    <style type="text/css">
        #finDrawClDiv label{line-height: 25px;}
        #finDrawClDiv span{line-height: 25px;}
        #finDrawClDiv2{padding: 12px;}
    </style>
</head>
<body>
	<section class="content">
    	<div class="row">
            <div class="col-md-12">
                <div class="box">
                	<div class="box-body">
						<div class="panel panel-default">
                            <div class="panel-body" style="padding-bottom:5px;">
                                <form class="form-horizontal" action="" method="post" id="dataForm">
                                    <input type="hidden" id="token" name="token" value="" />
                                    <input type="hidden" id="orderStat" name="wm[_NOT_IN$ORDER_STAT]" value="-1,0" />
                                	<div class="searchMenu">
                                	    <div>
                                            <label>提现方式：</label>
                                            <sk:select cssClass="form-control select" id="moneyWaySmall" name="wm[MONEY_WAY_SMALL_ID]" value="${page.wm.MONEY_WAY_SMALL_ID}" requiredInit="true" ajaxURL="${fundCenterV1}/fundFinanceDrawWayConfig/select?wm[DRAW_FLAG]=1">
                                                <option value="">请选择</option>
                                            </sk:select>
                                        </div>
                                        <div>
                                		    <label>订单编号：</label>
                                            <input type="text" class="form-control" name="wm[_LIKE$ORDER_NO]" value="${page.wm._LIKE$ORDER_NO}" placeholder="请输入订单编号">
                                        </div>
                                        <div>
                                            <label>提现时间：</label>
                                            <input id="createTimeStart" name="wm[_MORE_EQUAL$CREATE_TIME]" value="${page.wm._MORE_EQUAL$CREATE_TIME}"  type="text"  class="Wdate" 
											  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d 00:00:00',alwaysUseStartDate:true,maxDate:'#F{$dp.$D(\'createTimeEnd\')}',minDate:'#F{$dp.$D(\'createTimeEnd\',{d:-30,H:-23,m:-59,s:-59})}'})" /> 
											  <span class="pull-left">&nbsp;-&nbsp;</span>
											  <input id="createTimeEnd" name="wm[_LESS_EQUAL$CREATE_TIME]" value="${page.wm._LESS_EQUAL$CREATE_TIME}"  class="Wdate" 
								               onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',startDate:'%y-%M-%d 23:59:59',alwaysUseStartDate:true,minDate:'#F{$dp.$D(\'createTimeStart\')}',maxDate:'#F{$dp.$D(\'createTimeStart\',{d:+30,H:+23,m:+59,s:+59})}'})" />
                                        </div>
                                        <div class="mal10" >
                                            <button type="button"  class="btn btn-primary btn-sm"  onclick="findData()"><span class='glyphicon glyphicon-search'></span>查&nbsp;询</button>
                                            <!-- <button type="button"  class="btn btn-primary btn-sm"  onclick="addOrder()"><span class='glyphicon glyphicon-plus'></span>录&nbsp;单</button> -->
                                        </div>
                                	</div>
                                </form>
                        	</div>
						</div>
                        <table class="table table-hover table-condensed table-bordered table-striped" id="dataTable" >
                            <thead>
                            	<tr>
                                	<th data-field="index" data-align="center" data-formatter="indexFormatter" data-sortable="false" style="width:100px;">序号</th>
                                	<th data-field="orderNo" data-align="center" data-sortable="true">订单编号</th>
                                	<th data-field="moneyWaySmallId" data-align="center" data-sortable="false" data-formatter="drawFsFormatter">提现方式</th>
                                	<th data-field="userName" data-align="center" data-sortable="false">用户帐号</th>
                                    <th data-field="txName" data-align="center" data-sortable="false">姓名</th>
                                    <th data-field="bankAccount" data-align="center" data-sortable="true">提现帐号</th>
									<th data-field="drawMoney" data-align="center" data-sortable="true">提现金额</th>
									<th data-field="fee" data-align="center" data-sortable="true">手续费</th>
									<th data-field="realGet" data-align="center" data-sortable="true">实得金额</th>
                                    <th data-field="orderStat" data-align="center" data-sortable="true" data-formatter="orderStateFormatter">订单状态</th>
                                	<th data-field="createTime" data-align="center" data-sortable="true">下单时间</th>
                                	<th data-field="buttonField" data-align="center" data-sortable="true" data-formatter="buttonFieldFormatter">操作</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
       	</div>
	</section>
    <div id="finDrawClDiv" style="display: none;">
        <div id="finDrawClDiv2" class="panel panel-body">
        <form class="form-horizontal" action="" method="post" id="finDrawClForm">
            <input type="hidden" id="rowId" name="rowId" value="" />
            <input type="hidden" id="token2" name="token" value="" />
            <div class="form-group">
                <label class="col-xs-4 text-right">姓名 ：</label>
                <div class="col-xs-8"><span id="txName"></span></div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 text-right">提现方式：</label>
                <div class="col-xs-8"><span id="moneyWaySmallName"></span></div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 text-right">提现帐号：</label>
                <div class="col-xs-8"><span id="bankAccount"></span></div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 text-right">提现金额：</label>
                <div class="col-xs-8"><span id="drawMoney"></span></div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 text-right">手续费：</label>
                <div class="col-xs-8"><span id="fee"></span></div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 text-right">实得金额：</label>
                <div class="col-xs-8"><input type="text" id="realPay" name="realPay" value="" class="form-control" style="width: 80px;"/></div>
            </div>
            <div class="form-group">
                <label class="col-xs-4 text-right">备注：</label>
                <div class="col-xs-8"><textarea id="remarkBz" name="remarkBz" cols="55" rows="3" class="form-control"></textarea></div>
            </div>
        </form>
        </div>
    </div>
    <div id="finDrawCancelDiv" style="display: none;">
        <div id="finDrawClDiv2" class="panel panel-body">
            <form class="form-horizontal" action="" method="post" id="finDrawCancelForm">
                <input type="hidden" id="rowId" name="rowId" value="" />
                <input type="hidden" id="token2" name="token" value="" />
                <div class="form-group">
                    <label class="col-xs-4 text-right">作废原因：</label>
                    <div class="col-xs-8">
                        <select class="form-control select" id="cancalReasonId" name="cancelReasonId">
                            <option value="">请选择</option>
                        </select>
                        <input type="hidden" id="cancelReasonDesc" name="cancelReasonDesc" value=""/>
                    </div>
                </div>
            </form>
        </div>
    </div>
   <%@ include file="/view/common/footer.jsp"%>
</body>
<script>
// 提示信息
var msgg='<%=request.getAttribute("msg")%>';
if (msgg && msgg!=null && msgg!='null') { 
	  layer.msg(msgg);
}
var tableIndex = 0; // 添加修改的弹出框的ID
var finDrawStateDictList = "" // 订单状态字典数据
var finDrawWayDictList = "" // 提现方式字典数据

$(function(){
    $("#token").val(sessionStorage.getItem("token"));
    $("#token2").val(sessionStorage.getItem("token"));
    
    // 提现方式字典数据
    $.ajax({
    	type: "post",
    	url: "${fundCenterV1}/fundFinanceDrawWayConfig/select?token=" + sessionStorage.getItem("token"),
    	dataType: "json",
    	success: function(data){
    		finDrawWayDictList = data;
    	}
    });
    
    // 获取订单状态信息
    $.ajax({
    	type: "post",
    	url: "${fundCenterV1}/fundFinanceDrawDetail/finDrawStateDictList",
    	dataType: "json",
    	success: function(data){
    		finDrawStateDictList = data;
    	}
    });
    
    // 加载table 数据
    $("#dataTable").bootstrapTable({ 
        url: "${fundCenterV1}/fundFinanceDrawDetail/data.json",
        method:"get", 
        contentType: "application/x-www-form-urlencoded",
        pagination:true,
        sidePagination:"server",
        queryParams: function(params) {
            //alert(JSON.stringify(params));
            return $.extend({}, params, parseJson(decodeURIComponent($("#dataForm").serialize())));     
        }
    });
})

// 提现方式 字段格式化
function drawFsFormatter(value, row, index) {
    var finDrawWay = "";
    for(var i in finDrawWayDictList){
    	if(finDrawWayDictList[i]["value"] == value){
    		finDrawWay = finDrawWayDictList[i]["label"];
    	}
    }
    return finDrawWay;
}

// 订单状态 字段格式化
function orderStateFormatter(value, row, index) {
    var orderState = "";
    for(var i in finDrawStateDictList){
    	if(finDrawStateDictList[i]["value"] == value){
    		orderState = finDrawStateDictList[i]["label"];
    	}
    }
    return orderState;
}
    
// 操作字段格式化
function buttonFieldFormatter(value, row, index){
   var staffId = parent.$("#staffId").val();
   if(row.operateId > 0 && row.operateId != staffId){
       return "<span style='color:red;'>【" + row.operateName + "】处理中</span>";
   } else if(row.operateId == staffId){
       return "<button id='btn_edit' type='button' onclick='clOrder("+row.rowId+");' class='btn btn-default btn-sm'><span style='color:blue;'>【" + row.operateName + "】处理中</span></button>";
   } else {
       return "<button id='btn_edit' type='button' onclick='clOrder("+row.rowId+");' class='btn btn-default btn-sm'><span class='glyphicon glyphicon-pencil'></span>处 理</button>";;
   }
} 
    
// 查询
function findData(){
   $("#dataTable").bootstrapTable("refresh",{} ); 
} 

// 行点击事件
$(function(){
     $("body").on("click","table>tbody>tr",function(){
      $(this).css("background","#e1ecf1").siblings().css("background","");
   });
})

//处理订单
function clOrder(rowId){
   // 锁定订单
   $.ajax({
       type: "post",
       url: "${fundCenterV1}/fundFinanceDrawDetail/disposeOrder",
       data: {"rowId" : rowId, "token" : $("#token").val()},
       dataType: "json",
       async: false,
       success: function(data){
           if(data.code == 0){
        	   toDisposeOrderPage(rowId);
           } else if (data.code == -2) {
               window.location.href = "${sysManagerV1}/";
           } else {
               layer.msg(data.message);
               findData();
           }
       }
   });
}

// 展示订单处理页面
function toDisposeOrderPage(rowId){
	$("#remarkBz").val("");
	
	// 获取订单信息
	findOrderData(rowId);
	
	var bjtsIndex = layer.open({
        type: 1,
        title: "提现处理页面",
        area: ['480px', '420px'],
        content: $("#finDrawClDiv"),
        btn: ["确 认", "作废", "关 闭"], 
        yes: function(index, layero){
            var realPay = $("#realPay").val();
            if(!CheckUtil.isInt(realPay, "+") && !CheckUtil.isFloat(realPay, "+")){
                layer.msg("请填写正确的金额！");
                return;
            }
            
            $.ajax({
                type: "post",
                url: "${fundCenterV1}/fundFinanceDrawDetail/finDrawOrderFinish",
                data: new FormData($("#finDrawClForm")[0]),
                dataType:"json",
                processData: false,
                contentType: false,
                async:false,
                success: function(data){
                    if(data.code == 0){
                        layer.msg("标记完成成功！");
                        layer.close(bjtsIndex);
                        findData();
                    } else if (data.code == -2) {
                        window.location.href = "${sysManagerV1}/";
                    } else{
                        layer.msg(data.message);
                        layer.close(bjtsIndex);
                        findData();
                    }
                }
            });
        },
        btn2: function(index, layero){
        	// 获取作废原因并填充到页面
        	getReasonDictList();
        	
        	// 打开 作废原因选择页面
        	var reasonDivIndex = layer.open({
        		type: 1,
                title: "选择作废原因",
                area: ['350px', '200px'],
                content: $("#finDrawCancelDiv"),
                btn: ["确 认","关 闭"], 
                yes: function(index, layero){
                    layer.confirm("您确认作废吗？", {btn: ['确认', '取消']}, 
                        function(){
                    	    var cancalReasonId = $("#cancalReasonId").val();
                    	    var cancalReasonDesc = $("#cancalReasonId").find("option:selected").text();
                            $.ajax({
                                url: "${fundCenterV1}/fundFinanceDrawDetail/finDrawOrderCancel",
                                type: "post",
                                cache: false,
                                data: {rowId:rowId, cancalReasonId: cancalReasonId, cancalReasonDesc: cancalReasonDesc, token: $("#token").val()},
                                dataType:"json",
                                async:false,
                                success: function(data) {
                                   if (data.code == 0) { 
                                       layer.msg("退款成功", {icon: 1});
                                       findData();
                                   } else if(data.code == "-2"){
                                       window.location.href="${sysManagerV1}/";
                                   } else {
                                       layer.msg(data.message, {icon: 5});
                                   }
                                   layer.close(reasonDivIndex);
                                }
                            });
                    });
                }
        	})
        	return false;
        }
    });
}

//获取订单信息数据
function findOrderData(rowId){
 $.ajax({
     type: "post",
     url: "${fundCenterV1}/fundFinanceDrawDetail/getOrderData",
     data: {"rowId" : rowId, "token" : $("#token").val()},
     dataType: "json",
     success: function(data){
         if(data.code != 0){
             layer.msg(data.message);
             return;
         }
         
         data = data.data;
         $("#rowId").val(data.rowId);
         $("#txName").html(data.txName);
         $("#moneyWaySmallName").html(data.moneyWaySmallName);
         $("#bankAccount").html(data.bankAccount);
         $("#drawMoney").html(data.drawMoney + " 元");
         $("#fee").html(data.fee + " 元");
         $("#realPay").val(data.drawMoney);
     }
 });
}

//获取原因
function getReasonDictList(){
    var token = $("#token").val();
    $.ajax({
        type: "post",
        url: "${tradeV1}/tradeBaseReasons/reasonSelect",
        data: {"reasonTypeId" : 24, "token" : token},
        dataType: "json",
        success: function(data){
            if(data.length <= 0){
                return;
            }
         
            $("#cancalReasonId").empty();
            var option = "<option value=''>请选择</option>"
            $("#cancalReasonId").append(option);
         
            $.each(data, function (index, item) {
                option = "<option value='" + item.value + "'>" + item.label + "</option>"
                $("#cancalReasonId").append(option);
            });
        }
    });
}
</script>
</html>